import React, { Component } from 'react';
import { View, Text, Button } from '@tarojs/components';
import './index.scss';
import Taro from '@tarojs/taro';

export default class Index extends Component {
  state = {
    btnLoading: false,
  }
  componentWillMount () { }

  componentDidMount () { }

  componentWillUnmount () { }

  componentDidShow () { }

  componentDidHide () { }

  render () {
    return (
      <View className='index'>
        <Text className='text'>Hello world!   --</Text>
        <Text className='text'>Hello world!   --</Text>
        <Button
          id={'button'}
        className='button-login'
        type='primary'
        onClick={this.onLogin}
        hoverClass='hover'
        btnLoading={this.state.btnLoading}
        >
          微信登录授权
          </Button>
        <Button
          id={'button'}
          className={'button-normal-interactive-page'}
          type={'primary'}
          onClick={()=>this.onRouteToNormalInteractivePage()}
        >
          常见交互页
        </Button>
        <Button
          id={'button'}
          className={'button-auth-login'}
          type={'primary'}
          onclick={()=>{
            Taro.navigateTo({
              url:'/pages/AuthLogin/index'
            });
          }}
        >
          route to auth login
        </Button>
      </View>
    )
  }
  onLogin = ()=>{
    Taro.showToast({
      title:"登录成功",
      icon:'none',
      duration:2000,
      mask:true,
      complete:()=>{
        console.log("弹窗显示");
      }
    });
    // const appInstance = getApp();
    // console.log(appInstance);
    // console.log(appInstance.globalData);
    // this.setState({btnLoading:true});
    // Taro.nextTick(()=>{
    //   this.setState({btnLoading:false});
    // })
    // const that = this;
    // Page({
    //   data: {
    //     showActionSheet: false,
    //     groups: [
    //       {text: '示例菜单', value:1}
    //     ]
    //   },
    //   close: function() {
    //     this.setData({
    //       showActionSheet: false,
    //     })
    //   },
    //   btnClick(e) {
    //     console.log(e);
    //     this.close();
    //   }
    // });
    // return;
    // Taro.login({
    //   success:function(res) {
    //     Taro.getUserInfo({
    //       withCredentials: true,
    //       success:(info) => {
    //         if (res.code) {
    //           console.log('登录成功');
    //
    //         } else {
    //           console.log('登录失败！' + res.errMsg);
    //         }
    //       }
    //     })
    //   }
    // })
  }
  onRouteToNormalInteractivePage(){
    Taro.navigateTo({
      url:'/pages/NormalInteractivePage/NormalInteractivePage'
    });
  }
}
